Dynomotion

Group: DynoMotion Message: 12744 From: daveymahomh600e Date: 1/28/2016
Subject: Trouble Understanding Code

Hi Tom,


I have a few lines of code in an init file to stop the axis if an estop is detected...


    for (;;) // loop forever Estops
    {
        WaitNextTimeSlice();
               
        if (ReadBit(138))    // Estop bit
        {
        Jog(0,0.0);            // stop X
        Jog(1,0.0);            // stop Y
        Jog(2,0.0);            // stop A
        }
    }


For some reason, when the estop is pressed the bit shows active on the Digital IO screen, but the motion doesn't stop until I release the stop bit. You probably know this, but the bit is an opto input on a Kanalog board.


On a side note, there is also a forever loop in this program to monitor a start button. Is there any issues with having more than one forever loop within a single program?


Thanks in advance,

David.

Group: DynoMotion Message: 12745 From: Tom Kerekes Date: 1/28/2016
Subject: Re: Trouble Understanding Code
Hi David,

KFLOP has a quirk in that if you tell it to stop thousands of times per second it won't stop.  This is because as soon as it computes a 3rd order blended trajectory to stop it receives a new command to compute a new 3rd order blended trajectory to stop and never gets a chance to actually begin stopping.  Finally after you stop commanding to compute trajectories the last computed trajectory will get a chance to execute.

The solution is to only command it to stop once.  You can use the Debounce function in the ExternalButtons.c example that will both debounce the switch and return when the switch changes rather than what the level is.

You can not have more than one forever loop in a program as it wouldn't make logical sense.  That would be like saying to someone go and check if any mail arrived over and over forever and then when you are done with that go and check if someone is at the back door over and over forever.  Obviously the back door will never get around to being checked. 

The solution is to create a single loop that checks two things each time through the loop.   #1 go check the mail, #2 go check the back door, # 3 repeat.   Using this technique any number of things can be continuously performed in a single loop. 

There is one catch with this technique. None of the operations should "block" or take a significant amount of time to perform.  If you were to perform an operation that took a long time to complete all the other continuous operations would be blocked and go unserviced for that period of time.  If it is required to do something that takes a significant amount of time then the solution is to break it down into pieces (states) that can be each performed in an insignificant amount of time.  For example say you wish to activate a lubrication relay for 2 seconds each time a button is pushed.  Instead of delaying 2 seconds you would instead record the time the relay was turned on, then go off and do other things while frequently returning to see if it is time to turn the relay off. 

HTH
Regards
TK



On 1/28/2016 11:00 AM, david.m.stevenson@... [DynoMotion] wrote:
 

Hi Tom,


I have a few lines of code in an init file to stop the axis if an estop is detected...


    for (;;) // loop forever Estops
    {
        WaitNextTimeSlice();
               
        if (ReadBit(138))    // Estop bit
        {
        Jog(0,0.0);            // stop X
        Jog(1,0.0);            // stop Y
        Jog(2,0.0);            // stop A
        }
    }


For some reason, when the estop is pressed the bit shows active on the Digital IO screen, but the motion doesn't stop until I release the stop bit. You probably know this, but the bit is an opto input on a Kanalog board.


On a side note, there is also a forever loop in this program to monitor a start button. Is there any issues with having more than one forever loop within a single program?


Thanks in advance,

David.


Group: DynoMotion Message: 12746 From: David Stevenson Date: 1/28/2016
Subject: Re: Trouble Understanding Code
Hi Tom,

Thanks for your explanations... they make perfect sense.

Best regards,
David.

On 1/28/2016 3:47 PM, Tom Kerekes tk@... [DynoMotion] wrote:
 

Hi David,

KFLOP has a quirk in that if you tell it to stop thousands of times per second it won't stop.  This is because as soon as it computes a 3rd order blended trajectory to stop it receives a new command to compute a new 3rd order blended trajectory to stop and never gets a chance to actually begin stopping.  Finally after you stop commanding to compute trajectories the last computed trajectory will get a chance to execute.

The solution is to only command it to stop once.  You can use the Debounce function in the ExternalButtons.c example that will both debounce the switch and return when the switch changes rather than what the level is.

You can not have more than one forever loop in a program as it wouldn't make logical sense.  That would be like saying to someone go and check if any mail arrived over and over forever and then when you are done with that go and check if someone is at the back door over and over forever.  Obviously the back door will never get around to being checked. 

The solution is to create a single loop that checks two things each time through the loop.   #1 go check the mail, #2 go check the back door, # 3 repeat.   Using this technique any number of things can be continuously performed in a single loop. 

There is one catch with this technique. None of the operations should "block" or take a significant amount of time to perform.  If you were to perform an operation that took a long time to complete all the other continuous operations would be blocked and go unserviced for that period of time.  If it is required to do something that takes a significant amount of time then the solution is to break it down into pieces (states) that can be each performed in an insignificant amount of time.  For example say you wish to activate a lubrication relay for 2 seconds each time a button is pushed.  Instead of delaying 2 seconds you would instead record the time the relay was turned on, then go off and do other things while frequently returning to see if it is time to turn the relay off. 

HTH
Regards
TK



On 1/28/2016 11:00 AM, david.m.stevenson@... [DynoMotion] wrote:
 

Hi Tom,


I have a few lines of code in an init file to stop the axis if an estop is detected...


    for (;;) // loop forever Estops
    {
        WaitNextTimeSlice();
               
        if (ReadBit(138))    // Estop bit
        {
        Jog(0,0.0);            // stop X
        Jog(1,0.0);            // stop Y
        Jog(2,0.0);            // stop A
        }
    }


For some reason, when the estop is pressed the bit shows active on the Digital IO screen, but the motion doesn't stop until I release the stop bit. You probably know this, but the bit is an opto input on a Kanalog board.


On a side note, there is also a forever loop in this program to monitor a start button. Is there any issues with having more than one forever loop within a single program?


Thanks in advance,

David.



This email has been sent from a virus-free computer protected by Avast.
www.avast.com